/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 23.07.2005
 *
 *************************************************/
package fightplan.actions;

import javax.swing.JMenu;
import javax.swing.JMenuBar;

import fightplan.Mode;
import fightplan.business.Tournament;
import fightplan.business.TournamentListener;
import fightplan.views.ClientView;
import fightplan.views.MainView;

public class MenuFactory {

	public static JMenuBar createMenu(final MainView mainView) {
		JMenuBar menuBar = new JMenuBar();

		JMenu datei = new JMenu("Datei");
		menuBar.add(datei);

		datei.add(new NewTournamentAction(mainView));
		datei.add(new LoadTournamentAction(mainView));
		datei.add(new SaveTournamentAction(mainView));
		datei.addSeparator();
		datei.add(new RefreshAction(mainView));
		datei.addSeparator();
		datei.add(new ExitAction(mainView));

		JMenu edit = new JMenu("Bearbeiten");
		menuBar.add(edit);

		edit.add(mainView.getUndoRedoManager().getUndoAction());
		// edit.add(mainView.getUndoRedoManager().getRedoAction());
		edit.addSeparator();
		edit.add(new DeselectAllAction(mainView));
		edit.add(new SelectAllAction(mainView));

		JMenu data = new JMenu("Daten");
		menuBar.add(data);

		final ImportKyuXmlFightersAction xmlImport = new ImportKyuXmlFightersAction(mainView);
		data.add(xmlImport);
		data.add(new ImportExcelAction(mainView));
		data.add(new ImportExcelCategoriesAction(mainView));
		data.addSeparator();
		data.add(new WinnerReportAction(mainView));

		JMenu help = new JMenu("Hilfe");
		menuBar.add(help);

		help.add(new HelpAction(mainView));
		help.add(new AboutAction(mainView));

		//
		
		mainView.getTournament().addListener(new TournamentListener() {
			@Override
			public void tournamentChanged() {
				Tournament t = (Tournament) mainView.getTournament().getValue();
				xmlImport.setEnabled(t == null || (t.getMode() != Mode.SKRKYU_KINDER && t.getMode() != Mode.IPPONSHOBU  && t.getMode() != Mode.SKRKYU));
			}
		});
		
		return menuBar;

	}

	public static JMenuBar createMenu(ClientView clientView) {
		JMenuBar menuBar = new JMenuBar();

		JMenu datei = new JMenu("Datei");
		menuBar.add(datei);

		datei.add(new LoadSheetAction(clientView));
		datei.add(new SaveSheetAction(clientView, false));
		datei.add(new SaveSheetAction(clientView, true));
		datei.addSeparator();
		datei.add(new RefreshAction(clientView));
		datei.addSeparator();
		datei.add(new ExitAction(clientView));

		JMenu help = new JMenu("Hilfe");
		menuBar.add(help);

		help.add(new AboutAction(clientView));

		return menuBar;

	}

}
